<% 
String uploadUrl = (String) request.getAttribute("uploadUrl");
String key = (String) request.getAttribute("key");
String successActionRedirect = (String) request.getAttribute("successActionRedirect");
String accessId = (String) request.getAttribute("GoogleAccessId");
String policy = (String) request.getAttribute("policy");
String signature = (String) request.getAttribute("signature");
String acl = (String) request.getAttribute("acl");
%>		

<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
		<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
		<script type="text/javascript">
			$(document).ready(function() {			
				$('#button').click(function() {
					var formData = $('#fieldsForm').serialize();
					
					var callback = function(photoId) {
						var redir = $('#success_action_redirect').val() + photoId;
						$('#success_action_redirect').val(redir)
						$('#uploadForm').submit();
					};
									
					$.post("gstorage", formData, callback);
				});
			});
		</script>
	</head>
	
	<body>	
	
		<form id="fieldsForm" method="POST">
			<table>
				<tr>	
					<td>Title</td>
					<td><input type="text" name="title" /></td>
				</tr>
				<tr>	
					<td>Caption</td>
					<td>
						<input type="hidden" name="key" value="<%= key %>" />					
						<input type="text" name="caption" />
					</td>
				</tr>			
			</table>		
		</form>
			
		<form id="uploadForm" method="POST" action="<%= uploadUrl %>" enctype="multipart/form-data">
			<table>
				<tr>	
					<td>Upload</td>
					<td>
						<input type="hidden" name="key" value="<%= key %>" />
						<input type="hidden" name="GoogleAccessId" value="<%= accessId %>" />
						<input type="hidden" name="policy" value="<%= policy %>" />
						<input type="hidden" name="acl" value="<%= acl %>" />						
						<input type="hidden" id="success_action_redirect" name="success_action_redirect" value="<%= successActionRedirect %>" />
						<input type="hidden" name="signature" value="<%= signature %>" />
						<input type="file" name="file" />						
					</td>
				</tr>
				<tr>
					<td colspan="2"><input type="button" value="Submit" id="button"/></td>
				</tr>				
			</table>
		</form>
	</body>	
</html>